<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>@我通知列表</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <style>
	#more, .more{
		margin-top: 0px;
		padding-bottom: 15px;
		text-align: center;
	}
	.aui-user-view-cell p {
		font-size: 13px;
	}
	.message {
		margin-top: 3px;
		font-size: 15px;
	}
	.objectreply{
		margin: 3px 0 0 0;
		font-size: 14px;
		color: #333333;
		background-color: #eeeeee;
		padding: 8px 5px;
	}

    </style>
</head>
<body>
    <div class="aui-content" id="content">
        <ul class="aui-user-view" id="list">
            <!--li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/584/1169452_50.jpg?t=1445160758000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">金正恩</span>
                    <p>更新了动态：</p>
                    <h5 class='aui-text-default message'>@金三胖 你好啊</h5>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-comment"></font> 2</p>
				    </a>
                </div>
            </li>

            <li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/995/1991026_50.jpg?t=1416931477000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">大菲</span>
                    <p>回复了动态：</p>
                    <h5 class='aui-text-default message'>@金三胖 不抽烟可以 不喝酒不行啊！</h5>
	                <div class="objectreply">
	                    	从今天开始戒酒，求监督！如果你们再看见我喝一口的话................不用你们说！我！我自罚三杯！[再...
	                </div>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-comment"></font> 2</p>
				    </a>
                </div>
            </li>
            
            <li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/1241/2483709_50.png?t=1444614678000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">Cyanzq</span>
                    <p>回答了问题：<em class="aui-text-primary">phalcon必须啊。这个不要太牛逼。</em></p>
                    <h5 class='aui-text-default message'>phalcon必须啊。这个不要太牛逼。</h5>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-comment"></font> 2</p>
				    </a>
                </div>
            </li>
            
            <li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/995/1991026_50.jpg?t=1416931477000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">大菲</span>
                    <p>在 <em class="aui-text-primary">【果然叼】这款软件怎么实现的，太牛逼了吧？</em> 对回帖发表了评论</p>
                    <h5 class='aui-text-default message'>谢谢你回复我，怎么仿的呢？</h5>
	                <div class="objectreply">
	                    	金三胖：仿的界面
	                </div>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-comment"></font> 2</p>
				    </a>
                </div>
            </li>
            
            <li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/58/117988_50.jpg?t=1399199897000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">海诺者</span>
                    <p>在新闻 <em class="aui-text-primary">Git@OSC的SSH遭受攻击，建议暂时用https方式</em> 发表了评论</p>
                    <h5 class='aui-text-default message'>引用来自“金三胖”的评论晕死 提交不上，原来要换https 引用来自“海诺者”的评论https也处于半死中 引用来自“金三胖”的评论我提交上了o(∩_∩)o下午4点时有時没有，我也是桑心了</h5>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-comment"></font> 2</p>
				    </a>
                </div>
            </li>
            
            <li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/78/156070_50.jpg?t=1372671504000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">我爱小笼包</span>
                    <p>在博客 <em class="aui-text-primary">Mac系统升级到10.9(mavericks)时安装php扩展问题解决</em> 发表了评论</p>
                    <h5 class='aui-text-default message'>root也是各种无权限啊~~好难解决</h5>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-comment"></font> 2</p>
				    </a>
                </div>
            </li>
            
            <li class="aui-user-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="http://static.oschina.net/uploads/user/1125/2250952_50.jpg?t=1429083333000" width="48px" height="48px">
                <div class="aui-img-body">
                    <span class="aui-text-primary">宇智波唐嫣</span>
                    <p>回复了话题 <em class="aui-text-primary">大家平时除了逛开源中国之外，还经常活动在哪些论坛或者网站，快快分享出来！！！</em></p>
                    <h5 class='aui-text-default message'>引用来自“金三胖”的评论草榴社区 恩，已收藏，谢谢分享</h5>
				    <a class="aui-pull-left">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-time"></font> 5分钟前　<font class="aui-iconfont aui-icon-mobile"></font> iPhone</p>
				    </a>
				    <a class="aui-pull-right">
				        <p class='aui-ellipsis-1'><font class="aui-iconfont aui-icon-comment"></font> 2</p>
				    </a>
                </div>
            </li-->
            
        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/OSChinaApi.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
	var page = 0, ajaxTag = 0, uid = 0;
	apiready = function(){
		uid = $api.getStorage('user_uid');
		
		// 下拉刷新
		api.setRefreshHeaderInfo({
	        visible: true,
	        loadingImg: 'widget://image/ptr_pull.png',
	        bgColor: '#efeff4',
	        textColor: '#959595',
	        textDown: '下拉可刷新',
	        textUp: '松开立即刷新',
	        showTime: true
		}, function(ret, err){
			var more = $api.byId("more");
			if(more){
				 $api.remove(more);
			}
		    page = 0;
			// Window或者Frame页面滑动到底部事件,可用于实现滚动到底部，加载更多功能
			api.addEventListener({
			    name:'scrolltobottom',
			    extra:{
			        threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
			    }
			},function(ret,err){
			    getList( page );
			});
		    //从服务器加载数据，完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
		    getList( page );
		});
		
		// 首次加载时设置下拉刷新组件为刷新中状态
		api.refreshHeaderLoading();
		
	};
	
	/*
	 * 获取列表
	 * @param  integer pageIndex  	页码，第一页是从0开始的
	 */
	function getList( pageIndex ){
		if(ajaxTag){
			return false;
		}
		
		var listhtml = '';
		var url = OpenAPI.active_list + '&catalog=2&uid=' + uid + '&pageIndex=' + pageIndex;
	    var more = $api.byId("more");
	    if(more){
	        $api.text(more, '加载中...');
	    }

	    ajaxTag = 1;
		api.ajax({
		    url: url,
		    method: 'get',
		    timeout: 30,
		    dataType: 'text',
		    tag: ajaxTag,
		    returnAll: false,
		},function(ret,err){
			ajaxTag = 0;
		    if (ret) {
				var trans = api.require('trans');
				trans.parse({
				    data:ret
				},function(ret,err){
				    if(ret) {
						// 暂无消息
						if( pageIndex==0 && parseInt(ret.oschina.pagesize) == 0 ){
				    		$api.after($api.byId('list'), '<p id="more">暂无消息</p>');
				    		return false;
						}
						
						// 全部加载完毕
				    	if( !is_numeric(ret.oschina.pagesize) ){
				        	// 移除事件监听
							api.removeEventListener({
							    name: 'scrolltobottom'
							});
							var more = $api.byId("more");
							if(more){
								 $api.remove(more);
							}
				        	$api.after($api.byId('list'), '<p id="more">全部加载完毕</p>');
				        	return false;
				    	}
				    	
						var more = $api.byId("more");
						if(more){
							 $api.remove(more);
						}
						
						if(typeof(ret.oschina.activies.active.length) != 'number'){	// 对于只有一条数据的情况进行特殊处理
							ret.oschina.activies.active = JSON.parse('['+JSON.stringify(ret.oschina.activies.active)+']');
						}
						
						for(var i=0; i<ret.oschina.activies.active.length; i++){
							// 头像处理
				    		var portrait = '../image/widget_dface.png';
				    		if(typeof(ret.oschina.activies.active[i].portrait) == 'string' && ret.oschina.activies.active[i].portrait.length > 0){
				    			portrait = ret.oschina.activies.active[i].portrait;
				    		}
				    		
				    		// 数据类型的处理
				    		var openItem = '';
				    		switch( parseInt(ret.oschina.activies.active[i].catalog) )
				    		{
							case 0:		// 翻译类新闻
								openItem = "open_detail( "+ret.oschina.activies.active[i].objectID+", 'news' )";
							  break;
							case 1:		// 新闻
								openItem = "open_detail( "+ret.oschina.activies.active[i].objectID+", 'news' )";
							  break;
							case 2:		// 帖子
								openItem = "open_detail( "+ret.oschina.activies.active[i].objectID+", 'post' )";
							  break;
							case 3:		// 动弹
								openItem = "open_detail( "+ret.oschina.activies.active[i].objectID+", 'tweet' )";
							  break;
							case 4:		// 博客
								openItem = "open_detail( "+ret.oschina.activies.active[i].objectID+", 'blog' )";
							  break;
							default:
								log(ret.oschina.activies.active[i].catalog+' id:'+ret.oschina.activies.active[i].id);
				    		}
				    		
				    		// 客户端类型处理
				    		var appclient = 'PC';
				    		if(typeof(ret.oschina.activies.active[i].appclient) != 'undefined'){
				    			appclient = getAppClientName(ret.oschina.activies.active[i].appclient);
				    		}
				    		
				    		// 回复的原文
				    		var objectreply = '';
				    		if( typeof(ret.oschina.activies.active[i].objectreply)=='object'){
				    			objectreply = '<div class="objectreply"><font class="aui-text-primary">'+ret.oschina.activies.active[i].objectreply.objectname+'</font>：'+ htmlspecialchars(ret.oschina.activies.active[i].objectreply.objectbody) +'</div>';
				    		}
				    		
				    		// 下面各个类型是根据OSC的OpenAPI来的。
				    		// 所以有的类型在消息中心里是什么样我不知道，以后遇到了再加吧
				    		var objectType = '';
							switch( parseInt(ret.oschina.activies.active[i].objecttype) )
							{
							case 1:		// 开源软件
							  break;
							case 2:		// 帖子
							  break;
							case 3:		// 博客
							  break;
							case 4:		// 新闻
							  break;
							case 5:		// 代码
							  break;
							case 6:		// 职位
							  break;
							case 7:		// 翻译文章
							  break;
							case 8:		// 翻译段落
							  break;
							case 16:		// 新闻评论
								objectType = '在新闻 <em class="aui-text-primary">'+ret.oschina.activies.active[i].objecttitle+'</em> 发表了评论';
							  break;
							case 17:		// 讨论区答案
								objectType = '在 <em class="aui-text-primary">'+ret.oschina.activies.active[i].objecttitle+'</em> 对回帖发表了评论';
							  break;
							case 18:		// 博客评论
								objectType = '在博客 <em class="aui-text-primary">'+ret.oschina.activies.active[i].objecttitle+'</em> 发表了评论';
							  break;
							case 19:		// 代码评论
								objectType = '在代码 <em class="aui-text-primary">'+ret.oschina.activies.active[i].objecttitle+'</em> 发表了评论';
							  break;
							case 20:		// 职位评论
							  break;
							case 21:		// 翻译评论
							  break;
							case 32:		// 职位评论(怎么会有两个一样的，死红薯，写的什么文档)
							  break;
							case 100:		// 动弹
								objectType = '更新了动态';
							  break;
							case 101:		// 动弹回复
								objectType = '回复了动态';
							  break;
							default:
							}

							listhtml += '<li class="aui-user-view-cell aui-img" tapmode onclick="' + openItem + '">';
							listhtml += '<img class="aui-img-object aui-pull-left" src="' + portrait + '" width="48px" height="48px" tapmode onclick="openUserInfo( '+ ret.oschina.activies.active[i].authorid +' );event.cancelBubble=true;">';
							listhtml += '<div class="aui-img-body">';
							listhtml += '<span class="aui-text-primary">'+ ret.oschina.activies.active[i].author +'</span>';
							listhtml += '<p>'+objectType+'</p>';
							listhtml += '<h5 class="aui-text-default message">'+ ret.oschina.activies.active[i].message +'</h5>';
							listhtml += objectreply;
							listhtml += '<a class="aui-pull-left">';
							listhtml += '<p class="aui-ellipsis-1"><font class="aui-iconfont aui-icon-time"></font> '+ friendly_time(ret.oschina.activies.active[i].pubDate) +'　<font class="aui-iconfont aui-icon-mobile"></font> '+ appclient +'</p>';
							listhtml += '</a>';
							listhtml += '<a class="aui-pull-right">';
							listhtml += '<p class="aui-ellipsis-1"><font class="aui-iconfont aui-icon-comment"></font> '+ ret.oschina.activies.active[i].commentCount +'</p>';
							listhtml += '</a>';
							listhtml += '</div>';
							listhtml += '</li>';
						}
						
				        if(pageIndex == 0){
				        	$api.html($api.byId('list'), listhtml);
				        }else{
				        	$api.append($api.byId('list'), listhtml);
				        }
						page += 1;
				        $api.after($api.byId('list'), '<p id="more" tapmode onclick="getList('+page+')">点击加载更多</p>');
				        
				        setTimeout("notice_clear( 1 );", 2000);
				    }else{
					    if(more){
					        $api.text(more, '加载失败，点击重试');
					    }
				        log(err.msg);
				    }
				});
		    }else {
			    if(more){
			        $api.text(more, '加载失败，点击重试');
			    }
		        log('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode);
		    	showAjaxErrMsg(err.code);
		    }
		    api.refreshHeaderLoadDone();

		    setTimeout("api.parseTapmode()", 100);	// 等0.1秒在执行

		});
	}

</script>
</html>